<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>公告详情</title>
    <script>
        async function fetchAnnouncementDetail() {
            const params = new URLSearchParams(window.location.search);
            const announcementId = params.get('id');

            if (!announcementId) {
                document.getElementById('announcementDetail').innerHTML = '<p>错误ID</p>';
                return;
            }

            try {
                const response = await fetch(`announcement_detail.php?id=${announcementId}`);
                const announcement = await response.json();

                if (announcement && announcement.id) {
                    document.getElementById('announcementTitle').textContent = announcement.title;
                    document.getElementById('announcementContent').textContent = announcement.content;
                    document.getElementById('announcementDate').textContent = `发布时间: ${announcement.created_at}`;
                } else {
                    document.getElementById('announcementDetail').innerHTML = '<p>未找到公告</p>';
                }
            } catch (error) {
                console.error('Error fetching announcement detail:', error);
                document.getElementById('announcementDetail').innerHTML = '<p>Error fetching announcement details</p>';
            }
        }

        document.addEventListener('DOMContentLoaded', fetchAnnouncementDetail);
    </script>
</head>
<body>
    <h1>公告详情</h1>
    <div id="announcementDetail">
        <h2 id="announcementTitle"></h2>
        <p id="announcementContent"></p>
        <p id="announcementDate"></p>
    </div>
</body>
</html>
